package com.learn.smart.framework.util;

import java.io.InputStream;
import java.util.Properties;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


public class PropsUtil {
	
	private static final Logger log = LoggerFactory.getLogger(PropsUtil.class);
	
	public static Properties loadProps(String propertiesName){
		Properties pro = new Properties();
		try {
			InputStream in = Thread.currentThread().getContextClassLoader().getResourceAsStream(propertiesName);   
			pro.load(in);
			in.close();
		} catch (Exception e) {
			log.error("读取文件失败",e);
			e.printStackTrace();
		} 
		return pro;
	}
	
	public static String getString(Properties pro,String key){
		return pro.getProperty(key);
	}
	
	public static String getString(Properties pro,String key,String value){
		value = (pro.getProperty(key)==null?value:pro.getProperty(key));
		return value;
	}

	public static void main(String[] args) {
		Properties pro = loadProps("init.properties");
		System.out.println(pro.get("database.username"));

	}

}
